<template>
    <div>
        <my-head title="用户中心"></my-head>
        <van-form @submit="onSubmit">
            <van-field
                v-model="userInfo.mobile"
                name="用户名"
                label="用户名"
                placeholder="用户名"
            />
            <van-field
                v-model="userInfo.pwd"
                type="password"
                name="密码"
                label="密码"
                placeholder="密码"
            />
            <div style="margin: 16px;">
                <van-button round block type="info" native-type="submit">
                提交
                </van-button>
            </div>
        </van-form>
    </div>
</template>

<script>
import myHead from '@/components/head'
import { Toast } from 'vant'
import {useLogin} from '../utils/api'
export default {
    name: '',
    components: {
        myHead
    },
    data() { 
        return {
            userInfo: {
                mobile: '',
                pwd: ''
            }
            
        }
    },
    created() {

    },
    methods:{
        onSubmit() {
            useLogin(this.userInfo).then(res => {
                localStorage.setItem('token', res.data.token)
                if(this.$route.query.id) {
                    this.$router.push({
                        path:'/detail',
                        query: {
                            id: this.$route.query.id
                        }
                    })
                } else {
                    this.$router.back()
                }
            })
        } 
    }
 }
</script>

<style scoped>
</style>